package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesProduceMaterialCompleteCheck;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesProduceMaterialCompleteCheckDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:28:19
 */
public class MesProduceMaterialCompleteCheckConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesProduceMaterialCompleteCheckConverts.class);

    public static List<MesProduceMaterialCompleteCheckDTO> convert(List<MesProduceMaterialCompleteCheck> mesProduceMaterialCompleteCheckList) {
        if (CollectionUtils.isEmpty(mesProduceMaterialCompleteCheckList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesProduceMaterialCompleteCheckDTO> mesProduceMaterialCompleteCheckListResult = Lists.newArrayList();
        for (MesProduceMaterialCompleteCheck mesProduceMaterialCompleteCheck : mesProduceMaterialCompleteCheckList) {
            mesProduceMaterialCompleteCheckListResult.add(convert(mesProduceMaterialCompleteCheck));
        }
        return mesProduceMaterialCompleteCheckListResult;
    }

    public static MesProduceMaterialCompleteCheckDTO convert(MesProduceMaterialCompleteCheck mesProduceMaterialCompleteCheck) {
        try {
            return BeanUtils.copy(mesProduceMaterialCompleteCheck, MesProduceMaterialCompleteCheckDTO.class);
        } catch (Exception e) {
            LOG.error("MesProduceMaterialCompleteCheck到MesProduceMaterialCompleteCheckDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesProduceMaterialCompleteCheck到MesProduceMaterialCompleteCheckDTO转换失败", e);
        }
    }

    public static MesProduceMaterialCompleteCheck convert(MesProduceMaterialCompleteCheckDTO mesProduceMaterialCompleteCheckDTO) {
        try {
            return BeanUtils.copy(mesProduceMaterialCompleteCheckDTO, MesProduceMaterialCompleteCheck.class);
        } catch (Exception e) {
            LOG.error("MesProduceMaterialCompleteCheckDTO到MesProduceMaterialCompleteCheck转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesProduceMaterialCompleteCheckDTO到MesProduceMaterialCompleteCheck转换失败", e);
        }
    }
}